<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../css/font.css" rel="stylesheet" type="text/css" />
<jsp:useBean class="show.Main_show" id="mai" scope="request" />
<script language="javascript" src="../js/table.js" type="text/javascript"></script>
<script language="javascript">
window.onload = function()
{
     page = new Page(10,"excelTable","the_body");
}
</script>
</head>
<body background="../image/M}LHQTPE5WOUBI(R1PNW~YO.jpg">
<table style="color:#A73440; font-size:14px">
  <tr>
    <td width="240">
	  <p class="myFont">单击下面按钮以改变信息颜色</p>
      <button name="red" onclick="changeColor(1);">红</button>
      <button name="blue" onclick="changeColor(2);">蓝</button>
      <button name="yellow" onclick="changeColor(3);">黄</button>
      <p class="myFont">单击下面按钮以改变字体样式</p>
      <button name="red" onclick="changeFont();">华康字体</button>
	</td>
    <td width="403" align="right">
	<br />
	<p>填写下列表单以改变信息格式</p>
	<p>电邮：<input type="text" id="mail" /></p>
	<p>住址：<input type="text" id="adress" /></p><p><font id="sizeMess" size="+1" color="#FF0000" style="visibility:hidden">表格宽度只能控制在66~150！</font></p>
	<button name="tableSize" onclick="changeSize();">确定修改</button>
	</td>
  </tr>
</table>
<br />
<br />
<%
       String name = (String)session.getAttribute("name");
	   boolean isLog = false;
	   if(name!=null)
	   {
	         isLog = true;
	   }
	   out.print("<font id='infofont'>");
	   out.print("<div id='baseinfotable'><table id='excelTable' border='1' style='border-collapse:collapse'>");
	   out.print("<thead><tr><td width='100px' id='Schid'>学号</td><td width='100px' id='na'>姓名</td><td width='100px' id='ph'>电话</td><td width='100px' id='q'>QQ号</td><td width='100px' id='ma'>电子邮件</td><td width='100px' id='se'>性别</td><td width='100px' id='lo'>住址</td><td width='100px' id='bi'>生日</td></tr></thead><tbody id='the_body'>");
	   
	   for(int i = 0;i<mai.getNAME().size();i++)
	   {
	          out.print("<tr><td>"+mai.getID().get(i)+"</td>");
			  out.print("<td>"+mai.getNAME().get(i)+"</td>");
			  if(isLog)
			  {
			       out.print("<td>"+mai.getTEL().get(i)+"</td>");
				   out.print("<td>"+mai.getQQ().get(i)+"</td>");
				   out.print("<td>"+mai.getMAIL().get(i)+"</td>");
				   out.print("<td align='center'>"+mai.getSEX().get(i)+"</td>");
				   out.print("<td>"+mai.getLOCAL().get(i)+"</td>");
				   out.print("<td>"+mai.getBIRTH().get(i)+"</td></tr>");
			  }
			  else if(i<3)
			  {
			       out.print("<td>登</td>");
				   out.print("<td>陆</td>");
				   out.print("<td>以</td>");
				   out.print("<td>查</td>");
				   out.print("<td>看</td>");
				   out.print("<td>更多</td></tr>");
			  }
	   }
	   out.print("</tbody></table></div>");
	   out.print("</font>");
%>
<table>
  <tr>
    <td><a href="#" onclick="page.nextPage();">下一页</a></td>
    <td><a href="#" onclick="page.prePage();">上一页</a></td>
    <td><span id="pageindex"></span></td>
  </tr>
</table>
<div>
<!--<table id="ExcelMessTable" style="display:none" class="messBox">
<tr><td>just a test</td></tr>
</table>-->
<input id="exportButton" type="button" value="导出到EXCEL" 
       onclick="javascript:ExportToExcel(document.getElementById('excelTable'));"
	   onmouseover="document.getElementById('ExcelMessTable').style.display='block';" />
</div>

</body >
</html>
<script language="javascript">
function changeColor(col)
{
      var infofont = document.getElementById("infofont");
	  if(col==1)
	  {
	        infofont.color="#FF0000";
	  }else if(col==2)
	  {
	        infofont.color="#0000CC";
	  }else
	  {
	        infofont.color="#CCFF00";
	  }
}
function changeFont()
{
      var infofont = document.getElementById("infofont");
//	  alert("hekko");
	  infofont.className="myFont";
}
function changeSize()
{
      var sizeMess = document.getElementById("sizeMess");
	  var mail = document.getElementById("mail");
	  var adress = document.getElementById("adress");
	  var count = 1;
	  
	  var regexStr="^[0-9]*$";
      var regex=new RegExp(regexStr);
	  
	  if(mail.value.trim()=="")
	  {
	       mail.value = 100;
	  }
	  else
	  {
            if(!regex.test(mail.value))
			{
			      count = 0;
			}
	  }	  
	  if(adress.value.trim()=="")
	  {
	        adress.value = 100;
	  }
	  else
	  {
	        if(!regex.test(adress.value))
			{
			      count = 0;
			}
	  }
//	  alert("mail="+mail.value);	  
	  if(mail.value>=151||mail.value<=65||adress.value>=151||adress.value<=65||count!=1)
	  {
	        sizeMess.style.visibility = "visible";
			mail.value = "";
			adress.value = "";
	  }
	  else
	  {
	        sizeMess.style.visibility = "hidden";
			var ma = document.getElementById("ma");
			var lo = document.getElementById("lo");
			ma.width = mail.value+"px";
			lo.width = adress.value+"px";
			mail.value = "";
			adress.value = "";
	  }
}
</script>
<script language="javascript">
function ExportToExcel(tableId)  
{ 
      try{       
            var curTbl = document.getElementById("excelTable"); 
            var oXL = new ActiveXObject("Excel.Application"); 
            //创建AX对象excel  
            var oWB = oXL.Workbooks.Add(); 
            //获取workbook对象  
            var oSheet = oWB.ActiveSheet; 
            var lenRow = curTbl.rows.length; 
            //取得表格行数  
            for (i = 0; i < lenRow; i++) 
            { 
                var lenCol = curTbl.rows(i).cells.length; 
                //取得每行的列数  
                for (j = 0; j < lenCol; j++) 
                { 
                    oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText;  
                } 
            } 
            oXL.Visible = true; 
            //设置excel可见属性  
      }catch(e){ 
            if((!+'\v1')){ //ie浏览器  
              alert("无法启动Excel，请确保电脑中已经安装了Excel!\n\n如果已经安装了Excel，"+"请调整IE的安全级别。\n\n具体操作：\n\n"+"工具 → Internet选项 → 安全 → 自定义级别 → ActiveX 控件和插件 → 对未标记为可安全执行脚本的ActiveX 控件初始化并执行脚本 → 启用 → 确定"); 
           }else{ 
               alert("请使用IE浏览器进行“导入到EXCEL”操作！");  //方便设置安全等级，限制为ie浏览器  
           } 
       } 
}  
</script>